package com.jsgt.greekfire.ui.main.launch

import android.view.View
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.fhx.core.AppConfig
import com.fhx.core.base.BaseActivity
import com.fhx.core.goToActivity
import com.jsgt.greekfire.App
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.dialog.DialogUtils
import com.jsgt.greekfire.ui.home.entrance.addwallet.LoginWalletActivity
import com.jsgt.greekfire.ui.home.entrance.createwallet.RegisterWalletActivity
import com.jsgt.greekfire.ui.mine.user.language.LanguageActivity
import com.jsgt.greekfire.viewmodel.UserViewModel
import kotlinx.android.synthetic.main.activity_launch_temp.*

class LaunchTempActivity : BaseActivity(), View.OnClickListener {
    private val userViewModel: UserViewModel by lazy {
        ViewModelProvider(App.context).get(UserViewModel::class.java)
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_launch_temp
    }

    override fun needFitsSystemWindows(): Boolean {
        return false
    }

    override fun needSetStatusBar(): Boolean {
        return false
    }

    override fun main() {
        setStatusBar(R.color.transparent, false, R.color.white)
        viewCreate.setOnClickListener(this)
        viewAdd.setOnClickListener(this)
        textLanguage.setOnClickListener(this)

        userViewModel.versionLiveData.observe(this, Observer {
            if (AppConfig.getVersion()!! < it?.version!!) {
                DialogUtils.showUploadDialog(this, it)
            }
        })
        userViewModel.getVersion()
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.viewCreate -> {
                goToActivity<RegisterWalletActivity>()
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
            R.id.viewAdd -> {
                goToActivity<LoginWalletActivity>()
//                goToActivity<WalletListActivity>()
//                goToActivity<MainAtrActivity>()
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
            R.id.textLanguage -> {
                goToActivity<LanguageActivity> {
                    putExtra("from", 1)
                }
            }
        }
    }
}